<template>
  <div class="g-bd2 f-cb">
    <div class="g-sd2">
      <div class="g-wrap4 n-sgernav" id="singer-cat-nav">
        <h2 class="tit">全部</h2>
        <ul class="nav f-cb">
          <li>
            <a @click="changeTag('all', '全部歌手')">全部歌手</a>
          </li>
          <!--<li>-->
            <!--<a href="/discover/artist/signed/" class="cat-flag" data-cat="5001">入驻歌手</a>-->
          <!--</li>-->
        </ul>
        <div class="blk">
          <h2 class="tit">华语</h2>
          <ul class="nav f-cb">
            <li><a  class="cat-flag" data-cat="1001" @click="changeTag('1001', '华语男歌手')">华语男歌手</a>
            </li>
            <li><a  class="cat-flag" data-cat="1002" @click="changeTag('1002', '华语女歌手')">华语女歌手</a>
            </li>
            <li><a  class="cat-flag" data-cat="1003" @click="changeTag('1003', '华语组合')">华语组合/乐队</a>
            </li>
          </ul>
        </div>
        <div class="blk">
          <h2 class="tit">欧美</h2>
          <ul class="nav f-cb">
            <li><a  class="cat-flag" data-cat="2001" @click="changeTag('2001', '欧美男歌手')">欧美男歌手</a>
            </li>
            <li><a  class="cat-flag" data-cat="2002" @click="changeTag('2002', '欧美女歌手')">欧美女歌手</a>
            </li>
            <li><a  class="cat-flag" data-cat="2003" @click="changeTag('2003', '欧美组合')">欧美组合/乐队</a>
            </li>
          </ul>
        </div>
        <div class="blk">
          <h2 class="tit">日本</h2>
          <ul class="nav f-cb">
            <li><a class="cat-flag" data-cat="6001" @click="changeTag('6001', '日本男歌手')">日本男歌手</a>
            </li>
            <li><a class="cat-flag" data-cat="6002" @click="changeTag('6002', '日本女歌手')">日本女歌手</a>
            </li>
            <li><a  class="cat-flag" data-cat="6003" @click="changeTag('6003', '日本组合')">日本组合/乐队</a>
            </li>
          </ul>
        </div>
        <div class="blk">
          <h2 class="tit">韩国</h2>
          <ul class="nav f-cb">
            <li><a  class="cat-flag" data-cat="7001" @click="changeTag('7001', '韩国男歌手')">韩国男歌手</a>
            </li>
            <li><a class="cat-flag" data-cat="7002" @click="changeTag('7002', '韩国女歌手')">韩国女歌手</a>
            </li>
            <li><a class="cat-flag" data-cat="7003" @click="changeTag('7003', '韩国组合')">韩国组合/乐队</a>
            </li>
          </ul>
        </div>
        <div class="blk">
          <h2 class="tit">其他</h2>
          <ul class="nav f-cb">
            <li><a class="cat-flag" data-cat="4001" @click="changeTag('4001', '其他男歌手')">其他男歌手</a>
            </li>
            <li><a class="cat-flag" data-cat="4002" @click="changeTag('4002', '其他女歌手')">其他女歌手</a>
            </li>
            <li><a  class="cat-flag" data-cat="4003" @click="changeTag('4003', '其他组合')">其他组合/乐队</a>
            </li>
          </ul>
        </div>
      </div>
    </div>
    <div class="g-mn2">
      <div class="g-mn2c">
        <div class="g-wrap">

          <div class="u-title f-cb">
            <h3><span class="f-ff2">{{title}}</span></h3>
          </div>
          <div class="m-sgerlist">
            <ul class="m-cvrlst m-cvrlst-5 f-cb" id="m-artist-box">
              <li v-for="(item,index) in artists">
                <div class="u-cover u-cover-5">
                  <img :src="changeUrlToResizeImg(item.picUrl, 130)">
                  <router-link :to="{path:'artistDetail',query:{id:item.id}}" :title="item.name + '的音乐'" class="msk">
                  </router-link>
                  <!--<a :title="item.name + '的音乐'" href=" /artist?id=6452" class="msk"></a>-->
                </div>
                <p>
                  <!--<a href="/artist?id=6452" class="nm nm-icn f-thide s-fc0" :title="item.name + '的音乐'">{{item.name}}</a>-->
                  <router-link :to="{path:'artistDetail',query:{id:item.id}}" :title="item.name + '的音乐'" class="nm nm-icn f-thide s-fc0">
                    {{item.name}}
                  </router-link>
                  <!--<a v-if="item.accountId" class="icn u-icn u-icn-5" href="/user/home?id=97137413" :title="item.name +'的个人主页'"></a>-->
                </p>
              </li>
            </ul>
            <pagination-with-tag :page-num="pageNum" :pages="pages" :tag="tag" :get-data-with-page-num="getArtists"></pagination-with-tag>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>

    import {artist, getArtistsByTagId} from  './../service/getData';
    import PaginationWithTag from '../components/paginationWithTag'


  export default {
    name: 'artist',
    data () {
      return {
        list1: [],
        list2:[],
        artists: [],
        pageNum: 1,
        pages: 1,
        getArtists: this.getArtistByPageNum,
        title: "全部歌手",
        tag: "all"
      }
    },
    methods: {
      changeUrlToResizeImg(picUrl, size) {
        return picUrl.replace(/yunmusic_dev/, "resize_" + size + 'x' + size);
      },
      changeTag(tagId, title) {
        console.log(tagId)
        this.title = title;
        this.tag = tagId;
        if (tagId === 'all') {
          this.getArtistByPageNum(1)
          this.getArtists = this.getArtistByPageNum
        } else {
          this.getArtistByTagId(1, this.tag)
          this.getArtists = this.getArtistByTagId
        }

      },
      getArtistByPageNum(pageNum) {
        this.artists = []
        artist(this).get({
          page: pageNum,
          pageSize: 15
        }).then(res => {
          console.log(res)
          if (res.body.status === 200) {
            this.pageNum = res.body.data.page;
            this.pages = res.body.data.pages;
            this.artists = res.body.data.rows;
          }
        })
      },
      getArtistByTagId(pageNum, tagId) {
        console.log(tagId)
        this.artists = []
        getArtistsByTagId(this).get({
          page: pageNum,
          pageSize: 15,
          tagId: tagId
        }).then(res => {
          console.log(res)
          if (res.body.status === 200) {
            this.pageNum = res.body.data.page;
            this.pages = res.body.data.pages;
            this.artists = res.body.data.rows;
          }
        })
      }
    },
    mounted(){
      artist(this).get({
        page: this.pageNum,
        pageSize: 15
      }).then(res => {
        console.log(res)
        if (res.body.status === 200) {
          this.pageNum = res.body.data.page;
          this.pages = res.body.data.pages;
          this.artists = res.body.data.rows;
        }
      })

    },
    components: {PaginationWithTag}
  }
</script>

<style scoped>
  .g-bd, .g-bd1, .g-bd2, .g-bd3, .g-bd4, .g-bd5, .g-bd6, .g-bd7 {
    width: 980px;
    min-height: 700px;
    _height: 700px;
    margin: 0 auto;
    background-color: #fff;
    border: 1px solid #d3d3d3;
    border-width: 0 1px;
  }

  .g-bd2 {
    background: url(../image/wrap2.png) repeat-y center 0;
  }

  .g-sd2 {
    position: relative;
    float: left;
    width: 180px;
  }

  .n-sgernav {
    margin-top: 51px;
  }

  .g-wrap4 {
    padding: 0 10px 40px;
  }

  .n-sgernav .tit {
    height: 25px;
    padding-left: 14px;
    font-size: 16px;
    font-family: "Microsoft Yahei";
  }

  li, s {
    list-style: none;
  }

  .n-sgernav li {
    margin-bottom: 2px;
  }

  .n-sgernav li a {
    background: url(../image/singer.png) no-repeat 0 9999px;
  }

  .n-sgernav li, .n-sgernav li a {
    float: left;
    width: 160px;
    height: 29px;
    line-height: 29px;
  }

  .n-sgernav li a {
    width: 133px;
    padding-left: 27px;
    background-position: 0 -30px;
    color: #333;
  }

  .n-sgernav li a.z-slt, .n-sgernav li a.z-slt:hover {
    background-position: 0 0;
    text-decoration: none;
    color: #c20c0c;
  }

  .f-cb:after {
    clear: both;
    content: '.';
    display: block;
    height: 0;
    visibility: hidden;
  }

  .n-sgernav .blk {
    margin: 5px 0 0;
    padding-top: 16px;
    border-top: 1px solid #d3d3d3;
  }

  .n-sgernav .tit {
    height: 25px;
    padding-left: 14px;
    font-size: 16px;
    font-family: "Microsoft Yahei";
  }

  .g-mn2 {
    float: right;
    width: 100%;
    margin-left: -181px;
  }

  .g-mn2c {
    margin-left: 181px;
  }

  .g-wrap {
    padding: 40px;
  }

  .u-title {
    height: 40px;
    border-bottom: 2px solid #c20c0c;
  }

  .u-title h3 {
    float: left;
    font-size: 24px;
    font-weight: normal;
  }

  .f-ff2 {
    font-family: "Microsoft Yahei", Arial, Helvetica, sans-serif;
  }

  .s-fc3, a.s-fc3:hover {
    color: #666;
  }

  .u-title .more {
    float: right;
    margin-top: 14px;
  }

  .m-sgerlist .m-cvrlst {
    margin: 20px 0 0 -17px;
  }

  .m-cvrlst li {
    float: left;
    display: inline-block;
    width: 140px;
    height: 188px;
    overflow: hidden;
    padding: 0 0 30px 50px;
    line-height: 1.4;
  }

  .m-cvrlst-5 li {
    width: 130px;
    height: 154px;
  }

  .m-sgerlist .m-cvrlst li {
    padding-left: 17px;
  }

  .u-cover {
    position: relative;
    display: block;
  }

  .u-cover-5 {
    width: 130px;
    height: 130px;
  }

  img, .txt {
    border: 0;
  }

  .u-cover img {
    display: block;
    width: 100%;
    height: 100%;
  }

  .u-cover .bottom, .u-cover .msk, .n-musicsd .lst .avatar .msk {
    background: url(../image/coverall.png) no-repeat;
  }

  .m-cvrlst li p {
    width: 100%;
  }

  .m-sgerlist .m-cvrlst li p {
    margin-top: 8px;
  }

  .f-thide {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    word-wrap: normal;
  }

  .s-fc0, a.s-fc0:hover {
    color: #000;
  }

  .m-cvrlst li .nm {
    display: inline-block;
    max-width: 85%;
    vertical-align: middle;
  }

  .m-cvrlst li .nm-icn {
    max-width: 76%;
  }

  .m-cvrlst-5 li .nm-icn {
    float: left;
    max-width: 80%;
  }

  .f-tdn, .f-tdn:hover {
    text-decoration: none;
  }

  .u-icn, .u-title-1 .out .icon {
    background: url(../image/icon.png) no-repeat 0 9999px;
  }

  .u-icn, .u-icn2, .u-icn3 {
    display: inline-block;
    overflow: hidden;
    vertical-align: middle;
  }

  .u-icn-5 {
    width: 17px;
    height: 18px;
    background-position: 0 -740px;
  }

  .m-cvrlst-5 li .u-icn-5 {
    position: relative;
    float: right;
  }

  .m-cvrlst li p .u-icn {
    margin-top: -1px;
    _margin-top: -3px;
  }

  .u-cover .msk {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
  }

  .u-cover-5 .msk {
    background-position: 0 -680px;
  }

  .m-cvrlst li.line {
    margin-bottom: 12px;
    border-bottom: 1px dotted #999;
  }

  .m-cvrlst li.sml {
    height: 30px;
    width: 130px;
    padding-bottom: 0;
    line-height: 23px;
  }

  .m-cvrlst li.sml .nm-icn {
    max-width: 105px;
  }

  .m-cvrlst-5 li.sml .u-icn-5 {
    float: left;
    margin: 4px 0 0 2px;
  }
</style>

